package pl.maciejziarko.mshare.domain;

import pl.maciejziarko.mshare.utils.Check;

import java.util.Date;

/**
 * @author Maciej Ziarko
 */
public final class Account {

    private String username;
    private String email;
    private char[] password;
    private String hashedPassword;
    private String salt;
    private String firstName;
    private String lastName;
    private Date registration;

    public Account(String username) {
        Check.notEmpty(username, "Username cannot be null.");
        this.username = username;
    }

    public void erasePlaintextPassword() {
        for (int i = 0; i < password.length; ++i) {
            password[i] = 0;
        }
        password = null;
    }

    public String getUsername() {
        return username;
    }

    public char[] getPassword() {
        return password;
    }

    public void setPassword(char[] password) {
        this.password = password;
    }

    public String getSalt() {
        return salt;
    }

    public void setSalt(String salt) {
        this.salt = salt;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public Date getRegistration() {
        return registration;
    }

    public void setRegistration(Date registration) {
        this.registration = registration;
    }
    public String getHashedPassword() {
        return hashedPassword;
    }

    public void setHashedPassword(String hashedPassword) {
        this.hashedPassword = hashedPassword;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Account account = (Account) o;

        if (username != null ? !username.equals(account.username) : account.username != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return username != null ? username.hashCode() : 0;
    }
}
